import { Controller, Get, Request, Req, Query, Headers, Session, Ip, Param } from "@nestjs/common";
import { Request as ExpressRequest } from 'express';
@Controller('users')
export class UserController {
  @Get('req')
  handlerRequest(@Req() req: ExpressRequest, age: number, @Request() request: ExpressRequest) {
    console.log(req.url);
    console.log('number', age)
    console.log(request.method)
    return 'handlerRequest'
  }

  @Get('query')
  handleQuery(@Query() req: any, @Query('id') id: string) {
      console.log(req)
      console.log('id',id)
      return `query id ${id}`
  }

  @Get('headers')
  handlerHeaders(@Headers() headers: any, @Headers('accept') accept: string) {
    console.log(headers)
    console.log('accept', accept)
    return `header accept ${accept}`
  }

  @Get('session')
  handlerSession(@Session() session: any, @Session('pageView') pageView: string) {
    console.log(session)
    console.log('pageView', pageView)
    if(session.pageView) {
      session.pageView++
    } else {
      session.pageView = 1
    }
    return `session pageView ${session.pageView}`
  }

  @Get('ip')
  getUserIp(@Ip() ip: string) {
    console.log(ip)
    return `ip ${ip}`
  }

  @Get(':username/info/:age')
  getUserNameInfo(@Param() param: any, @Param('username') username: string, @Param('age') age: string) {
    console.log(param)
    console.log('username', username)
    console.log('age', age)
    return `username ${username} age ${age}`
  }

  @Get('star/ab*cd')
  getStar() {
    return 'star ab*cd'
  }
}
